<?php
session_start();

// Open database connection
$dbHost = "sid3.comp.nus.edu.sg";
$dbHostPort="1521";
$dbServiceName = "sid3.comp.nus.edu.sg";
$usr = "A0103863";
$pswd = "cs2102std";
$dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$dbHost.")(PORT=".$dbHostPort."))(CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))";
$dbConn = oci_connect($usr,$pswd,$dbConnStr);

if(!$dbConn)
{
	$err = oci_error();
	print('Could not establish a database connection: ' . $err['message']);
}
else
{
	// Insert a new ad into the database
	$strSQL = "DELETE FROM ad a WHERE a.student='".$_SESSION['user']."' AND a.time_created=to_date('".$_GET['date']."', 'Dy DD-Mon-YYYY HH24:MI:SS')";
	
	$stmt = oci_parse($dbConn,$strSQL);
	if (!oci_execute($stmt)) {
		$err = oci_error($stmt);
		print('Query failed: '.$err['message']);
	}else{
		print "<h1>The ad was successfully deleted from Stewie's market</h1>";
		print "<a href='my_ads.php'>Go back to your ads</a>";
	}
	
}
?>


